//
//  TagApi.swift
//  MT
//
//  Created by M on 2020/1/4.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit

/// 网络
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum TagApi {
    
    /// 列表
    case list(type: Int)
    
    /// 保存新tag
    case save(params: [[String:Any]], type: Int)
    
}

// MARK: ------------------ Api 参数 ----------------------
extension TagApi: MTTargetType {

    /// 请求头
    public var headers: [String : String]? {
        guard let accessToken = UserDefaults.MTUserCenter.token.storedString else { return nil }
        return ["Access-Token": accessToken]
    }
    
    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
            /// 热门列表
        case .list:
            return "/tag/list"
            
            /// 最新列表
        case .save:
            return "/tag/save"
            
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        return .post
    }
    
    /// 参数
    var params: [String: Any]? {
        switch self {
        case let .list(type):
            return ["tagType": type]
            
        case let .save(params, type):
            return ["list": params,
                    "type": type]
        }
    }
    
}
